﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Comm
{
    public class ClientCache
    {
        public static void Add(string key, object obj)
        {
            int minutes = Config.CacheDefaultTime;
            Add(key, obj, minutes);
        }

        public static void Add(string key, object obj, int minutes)
        {
            DateTime expiredTime = DateTime.Now;
            expiredTime = expiredTime.AddMinutes(minutes);
            System.Web.HttpRuntime.Cache.Insert(key, obj, null, expiredTime, TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Low, null);
        }

        public static void Add(string key, object obj, System.Web.Caching.CacheItemRemovedCallback callback)
        {
            int minutes = Config.CacheDefaultTime;
            Add(key, obj, minutes, callback);
        }

        public static void Add(string key, object obj, int minutes, System.Web.Caching.CacheItemRemovedCallback callback)
        {
            DateTime expiredTime = DateTime.Now;
            expiredTime = expiredTime.AddMinutes(minutes);
            System.Web.HttpRuntime.Cache.Insert(key, obj, null, expiredTime, TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Low, callback);
        }

        public static void Add(string key, object obj, DateTime time, string path)
        {
            System.Web.HttpRuntime.Cache.Insert(key, obj, new System.Web.Caching.CacheDependency(path), time, TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Low, null);

        }

        public static T Get<T>(string key)
        {
            return (T)Get(key); ;
        }

        public static object Get(string key)
        {
            return System.Web.HttpRuntime.Cache.Get(key);
        }
    }
}
